package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.IntepralSetting;
import com.ruoyi.system.domain.Point;
import com.ruoyi.system.mapper.IntepralSettingMapper;
import com.ruoyi.system.service.IntepralSettingService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (IntepralSetting)表服务实现类
 *
 * @author makejava
 * @since 2021-02-27 08:47:32
 */
@Service("intepralSettingService")
public class IntepralSettingServiceImpl implements IntepralSettingService {
    @Resource
    private IntepralSettingMapper intepralSettingDao;

    /**
     * 通过ID查询单条数据
     *
     * @param Id 主键
     * @return 实例对象
     */
    @Override
    public IntepralSetting queryById(Integer Id) {
        return this.intepralSettingDao.queryById(Id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<IntepralSetting> queryAllByLimit(int offset, int limit) {
        return this.intepralSettingDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param intepralSetting 实例对象
     * @return 实例对象
     */
    @Override
    public IntepralSetting insert(IntepralSetting intepralSetting) {
        this.intepralSettingDao.insert(intepralSetting);
        return intepralSetting;
    }

    /**
     * 修改数据
     *
     * @param intepralSetting 实例对象
     * @return 实例对象
     */
    @Override
    public int update(IntepralSetting intepralSetting) {

        return this.intepralSettingDao.update(intepralSetting);
    }

    /**
     * 通过主键删除数据
     *
     * @param Id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer Id) {
        return this.intepralSettingDao.deleteById(Id) > 0;
    }

    @Override
    @Transactional
    public long addIntepral(String user_id,Integer id) {
        IntepralSetting intepralSetting = intepralSettingDao.queryById(1);
        String item;
        if (intepralSetting!=null){
            Point point = new Point();
            point.setUser_id(user_id);
            double score = 0;
            switch (id) {
                case 1:
                    score = intepralSetting.getBindphone();
                    point.setPoint((int)score);
                    item = "绑定手机";
                    break;
                case 2:
                    score = intepralSetting.getRegist();
                    point.setPoint((int)score);
                    item = "注册账号";
                    break;

                case 3:
                    score = intepralSetting.getUpload();
                    point.setPoint((int)score);
                    item = "上传作品";
                    break;
                case 4:
                    score = intepralSetting.getShare();
                    point.setPoint((int)score);
                    item = "分享";
                    break;
                case 5:
                    score = intepralSetting.getComment();
                    point.setPoint((int)score);
                    item = "评论";
                    break;
                case 6:
                    score = intepralSetting.getSign();
                    point.setPoint((int)score);
                    item = "报名比赛";
                    break;
                case 7:
                    score = intepralSetting.getSubmit();
                    point.setPoint((int)score);
                    item = "提交作品";
                    break;
                case 8:
                    score = intepralSetting.getStudy();
                    point.setPoint((int)score);
                    item = "学习视频";
                    break;
                case 9:
                    score = intepralSetting.getLookwork();
                    point.setPoint((int)score);
                    item = "浏览作品";
                    break;
                case 10:
                    score = intepralSetting.getGood();
                    point.setPoint((int)score);
                    item = "点赞";
                    break;
                default:
                    break;
            }
            int intepral = intepralSettingDao.addIntepral(point);
            return   intepral;
        }

        return 0;
    }

    @Override
    public long reduceIntepral(String user_id, Integer id) {
        IntepralSetting intepralSetting = intepralSettingDao.queryById(1);
        String item;
        if (intepralSetting!=null){
            Point point = new Point();
            point.setUser_id(user_id);
            double score = 0;
            switch (id) {
                case 1:
                    score = intepralSetting.getBindphone();
                    point.setPoint((int)score);
                    item = "绑定手机";
                    break;
                case 2:
                    score = intepralSetting.getRegist();
                    point.setPoint((int)score);
                    item = "注册账号";
                    break;

                case 3:
                    score = intepralSetting.getUpload();
                    point.setPoint((int)score);
                    item = "上传作品";
                    break;
                case 4:
                    score = intepralSetting.getShare();
                    point.setPoint((int)score);
                    item = "分享";
                    break;
                case 5:
                    score = intepralSetting.getComment();
                    point.setPoint((int)score);
                    item = "评论";
                    break;
                case 6:
                    score = intepralSetting.getSign();
                    point.setPoint((int)score);
                    item = "报名比赛";
                    break;
                case 7:
                    score = intepralSetting.getSubmit();
                    point.setPoint((int)score);
                    item = "提交作品";
                    break;
                case 8:
                    score = intepralSetting.getStudy();
                    point.setPoint((int)score);
                    item = "学习视频";
                    break;
                case 9:
                    score = intepralSetting.getLookwork();
                    point.setPoint((int)score);
                    item = "浏览作品";
                    break;
                case 10:
                    score = intepralSetting.getGood();
                    point.setPoint((int)score);
                    item = "点赞";
                    break;
                default:
                    break;
            }
            return intepralSettingDao.addIntepral(point);
        }
        return 0;
    }
}
